Git Product home page Git Product logo

swapi-python's Introduction

swapi-python

https://badge.fury.io/py/swapi.png https://travis-ci.org/phalt/swapi-python.png?branch=master https://pypip.in/d/swapi/badge.png

A Python helper library for swapi.co - the Star Wars API

NOTE: Tests will run against hosted API as opposed to data from github repo

Installation

At the command line:

$ pip install swapi

Basic Usage

To use swapi-python in a project:

import swapi

All resources are accessible through the top-level get_resource() methods:

luke = swapi.get_person(1)
tatooine = swapi.get_planet(1)

Methods

These are the top-level methods you can use to get resources from swapi.co. To learn more about the models and objects that are returned, see the models page.

get_person(id)

Return a single Person resource.

Example:

swapi.get_person(1)
>>> <Person - Luke Skywalker>

get_planet(id)

Return a single Planet resource.

Example:

swapi.get_planet(1)
>>> <Planet - Tatooine>

get_starship(id)

Return a single Starship resource.

Example:

swapi.get_starship(6)
>>> <Starship - Death Star>

get_vehicle(id)

Return a single Vehicle resource.

Example:

swapi.get_vehicle(4)
>>> <Vehicle - Sand Crawler>

get_film(id)

Return a single Film resource.

Example:

swapi.get_film(1)
>>> <Film - A New Hope>

get_all("resource")

Return a QuerySet containing all the items in a single resource. See the `models` page for more information on the models used in swapi-python.

Example:

swapi.get_all("films")
>>> <FilmQuerySet - 6>

swapi-python's People

Contributors

phalt avatar windwaker avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

swapi-python's Issues

pip installing swapi

When I tried to install swapi using pip, it worked all fine and well on my WSL. But then when I tried to run a program which imported the module, it crashed saying there was no package called settings. As shown in the screenshot below.

image

ModuleNotFoundError: No module named 'settings'

from django.shortcuts import render

Create your views here.

def index(request):
import swapi

films = swapi.get_all("films")
context = {
    'list': films
}
return render( request, 'index.html', context)

Internal Server Error: /films/
Traceback (most recent call last):
File "/home/acuta/Документи/Python/django/part_10/.venv/lib/python3.10/site-packages/swapi/swapi.py", line 3, in
from swapi.utils import query, all_resource_urls
File "/home/acuta/Документи/Python/django/part_10/.venv/lib/python3.10/site-packages/swapi/utils.py", line 1, in
import requests
File "/home/acuta/Документи/Python/django/part_10/.venv/lib/python3.10/site-packages/requests/init.py", line 58, in
from . import utils
File "/home/acuta/Документи/Python/django/part_10/.venv/lib/python3.10/site-packages/requests/utils.py", line 26, in
from .compat import parse_http_list as _parse_list_header
File "/home/acuta/Документи/Python/django/part_10/.venv/lib/python3.10/site-packages/requests/compat.py", line 7, in
from .packages import chardet
File "/home/acuta/Документи/Python/django/part_10/.venv/lib/python3.10/site-packages/requests/packages/init.py", line 3, in
from . import urllib3
File "/home/acuta/Документи/Python/django/part_10/.venv/lib/python3.10/site-packages/requests/packages/urllib3/init.py", line 10, in
from .connectionpool import (
File "/home/acuta/Документи/Python/django/part_10/.venv/lib/python3.10/site-packages/requests/packages/urllib3/connectionpool.py", line 38, in
from .response import HTTPResponse
File "/home/acuta/Документи/Python/django/part_10/.venv/lib/python3.10/site-packages/requests/packages/urllib3/response.py", line 5, in
from ._collections import HTTPHeaderDict
File "/home/acuta/Документи/Python/django/part_10/.venv/lib/python3.10/site-packages/requests/packages/urllib3/_collections.py", line 1, in
from collections import Mapping, MutableMapping
ImportError: cannot import name 'Mapping' from 'collections' (/usr/lib/python3.10/collections/init.py)

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File "/home/acuta/Документи/Python/django/part_10/.venv/lib/python3.10/site-packages/django/core/handlers/exception.py", line 55, in inner
response = get_response(request)
File "/home/acuta/Документи/Python/django/part_10/.venv/lib/python3.10/site-packages/django/core/handlers/base.py", line 197, in _get_response
response = wrapped_callback(request, *callback_args, **callback_kwargs)
File "/home/acuta/Документи/Python/django/part_10/starwars/films/views.py", line 6, in index
import swapi
File "/home/acuta/Документи/Python/django/part_10/.venv/lib/python3.10/site-packages/swapi/init.py", line 7, in
from .swapi import (
File "/home/acuta/Документи/Python/django/part_10/.venv/lib/python3.10/site-packages/swapi/swapi.py", line 19, in
import settings
ModuleNotFoundError: No module named 'settings'
[10/Sep/2023 10:53:55] "GET /films/ HTTP/1.1" 500 222569

Get all attributes of character?

A small question... I may not be reading the docs properly, but here it is...
Let's say I store Luke Skywalker's data in a variable by using
import swapi
luke = swapi.get_person(1).
I want to know all about Skywalker, but if I print (luke), I simply get the output
<Person -- Luke Skywalker>.
Is there any way to print all of Skywalker's information without having to seperately call everything (luke.name, luke.height, etc.)?
If not, show me how I can help create this feature.

Python 3 sorting

swapi-python currently breaks with Python 3.

The order_by() method on BaseQuerySet doesn't like the lambda. Fix is urgently needed.

pip install fails with Python 3.4

I'm trying to install on a Win7 machine with Python 3.4 and get this error:
Command "C:\Python34\python.exe -c "import setuptools, tokenize;file='C:\Users\johng42\AppData\Local\Temp\pip-build-gnwse7tv\ujson\setup.py';exec(compile(getattr(tokenize, 'open', open)(file).read().replace('\r\n', '\n'), file, 'exec'))" install --record C:\Users\johng42\AppData\Local\Temp\pip-veof5j7j-record\install-record.txt --single-version-externally-managed --compile" failed with error code 1 in C:\Users\johng42\AppData\Local\Temp\pip-build-gnwse7tv\ujson

I get the same error if I copy the wheel file locally and try to install it.

swapi.co is down!!!

Unfortulately swapi.co is not maintained anymore, and the service is currently down. This is an branch of SWAPI that will be supported going forward.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.