REST API lib creator
REST API lib creator is a boilerplate-free way for creating libs for RESTful APIs (specially the ones created using Django REST framework - but certainly adaptable for other frameworks).
NOTES:
- This is a port for a personal project I made for myself. It may or may not solve your needs (it solves mine).
- This is still alpha. I opened this on GH just so I can see if this is something I should improve (or not).
Examples:
- The bare minimum for creating your own lib:
from rest_api_lib_creator.core import ViewsetRestApiLib
class User(ViewsetRestApiLib):
base_api_url = 'http://super.cool/api/users'
- With this you can play around with your API:
users = User.list() # Triggers a requests.get with url=http://super.cool/api/users
isinstance(users[0], User)
user = User.create(first_name='Filipe', last_name='Waitman', email='filwaitman@gmail.com', photo=open('image.png', 'rb')) # Triggers a requests.post with url=http://super.cool/api/users and data={'first_name': 'Filipe', 'last_name': 'Waitman', 'email': 'filwaitman@gmail.com'} and files={'photo': <file binary content>}
# Similarly to the call above you could create an empty object and save it:
user = User()
user.first_name = 'Filipe'
user.last_name = 'Waitman'
user.email = 'filwaitman@gmail.com'
user.photo = open('image.png', 'rb')
user.save() # Triggers a requests.post with url=http://super.cool/api/users and data={'first_name': 'Filipe', 'last_name': 'Waitman', 'email': 'filwaitman@gmail.com'} and files={'photo': <file binary content>}
isinstance(user, User)
print(user.id) # Prints the user id (assuming the API returned this field)
print(user.first_name) # )rints the user first name (assuming the API returned this field)
user.first_name = 'New name'
user.save() # Triggers a requests.patch with url=http://super.cool/api/users/<user-id> and data={'first_name': 'New name'}
user.delete() # Triggers a requests.delete with url=http://super.cool/api/users/<user-id>
- If your resource return other nested resources you can parse them as well:
class Pet(ViewsetRestApiLib):
base_api_url = 'http://super.cool/api/pets'
nested_objects = {
'owner': User,
}
pet = Pet.retrieve('pet-id')
isinstance(pet, Pet)
isinstance(pet.owner, User)
- See a more complete (and real world) example here
- You can see all possible customizations here (someday I'll improve this doc).
Special thanks:
- Django REST framework - you're the best, seriously.
- Stripe-python lib - which I used as an inspiration to create this project.
Development:
Run linter:
pip install -r requirements_dev.txt
isort -rc .
tox -e lint
Run tests via tox:
pip install -r requirements_dev.txt
tox
Release a new major/minor/patch version:
pip install -r requirements_dev.txt
bump2version <PART> # <PART> can be either 'patch' or 'minor' or 'major'
Upload to PyPI:
pip install -r requirements_dev.txt
python setup.py sdist bdist_wheel
python -m twine upload dist/*
Contributing:
Please open issues if you see one, or create a pull request when possible. In case of a pull request, please consider the following:
- Respect the line length (132 characters)
- Write automated tests
- Run
toxlocally so you can see if everything is green (including linter and other python versions)
Metadata
Release files for rest-api-lib-creator 0.4.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | |
|---|---|---|---|---|
| rest-api-lib-creator-0.4.0.tar.gz | 7.1 kB | Without provenance | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| rest_api_lib_creator-0.4.0-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 15.5 kB
Release files / rest-api-lib-creator-0.4.0.tar.gz
| Download URL | rest-api-lib-creator-0.4.0.tar.gz |
|---|---|
| Size | 7.1 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
6f92a0c8565dec98f37cd212b447eba6f0eb8ebd8b99a936202be8dbd7ea86e1
|
|
BLAKE2b-256 checksum How to use checksums |
a76c92eba85808e45626ec5b593d1d093ee5f91579b460aee1886fd5849f1d2f
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/3.1.1 pkginfo/1.5.0.1 requests/2.23.0 setuptools/45.3.0 requests-toolbelt/0.9.1 tqdm/4.46.0 CPython/3.6.9
|
Release files / rest_api_lib_creator-0.4.0-py3-none-any.whl
| Download URL | rest_api_lib_creator-0.4.0-py3-none-any.whl |
|---|---|
| Size | 8.4 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
c9a243a7cc8c65fa3a487c88e87b2df6ee82573039651a59c5bde609c765d341
|
|
BLAKE2b-256 checksum How to use checksums |
3d8f7888bca0f71bbd9d7b38f1f2d4ef01d9d77afbbde2605b4667b4295b3d82
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/3.1.1 pkginfo/1.5.0.1 requests/2.23.0 setuptools/45.3.0 requests-toolbelt/0.9.1 tqdm/4.46.0 CPython/3.6.9
|
Security for rest-api-lib-creator 0.4.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.