Skip to main content

A python package that simplifies the process of making API requests to 42's API.

Project description

ptapi42

A python package that simplifies the process of making API requests to 42's API. With this package, developers can quickly and easily access the 42 API's functionality, without having to deal with the complexities of working directly with it.

Acknowledgments

This API is highly influenced by dropi, which is available as a package as well. However, with 42 API's updates from earlier this year, dropi became obsolete, or difficult to use, as it isn't being maintained. As a result, we decided to create a new API based on dropi, but with some differences.

Differences from dropi

While our API is heavily influenced by dropi, it includes some extra features:

  • Configurable Logger: We've implemented a logging system using the logging library, which provides you with more control over the messages being logged. You can use it to debug and monitor your application. The logger's level can be set to different levels (DEBUG, INFO, WARNING, ERROR, CRITICAL) to filter out the messages that aren't relevant to your needs.

  • Exception Raising: You can configure the API to raise exceptions whenever there's an error. This way, you'll be able to handle the errors in your own way, rather than having the API fail silently.

  • Rate Limiting: You can configure the number of requests per second you want to do to the API. This can help you avoid reaching the API's rate limit and getting blocked.

  • Maintenance and New Features: This project is actively maintained, so you can expect it to be updated with new features and fixes when needed. We're also working on adding a better mass_request function to simplify requests that involve multiple API endpoints.

Support

ptapi42 is maintained by the 42 Portugal association, which provides resources and support to improve the API and address any issues. If you have any questions or feedback, feel free to reach out to us in issues.

How to install (in prog)

pip install ptapi42

How To Use Api

from ptapi42 import Api42, Api42Request

api: Api42 = Api42()

# Making a simple GET request
campus_id = 'porto'
params: dict = {
	'filter': {
		'pool_month': 'february',
		'pool_year': '2023'
	}
}
url = f'campus/{campus_id}/users'
users = api.get(url=url, params=params)

# Making a mass_request
reqs: list = []
for user in users:
	api_req = Api42Request(url=f"users/{user['id']}")
	reqs.append(api_req)
user_info = api.mass_request('GET', reqs)

Api Reference

How To Configure Api

The Api has some configurations.

from ptapi42 import Api42

api: Api42 = Api42()

Configure if you want Api42 to raise exceptions

api.raises = True

Configure the max number of requests per second

api.requests_per_second = 8

Configure Api log level

api.log_lvl = 'DEBUG'
api.log_lvl = 'INFO'
api.log_lvl = 'WARNING'
api.log_lvl = 'ERROR'
api.log_lvl = 'FATAL'

Running Tests (dev)

  1. Cloning the repository and switching to the testing branch
git clone git@github.com:42-Portugal/ptapi42.git
cd ptapi42
  1. Create a python environment and install the required packages
python -m venv venv
source venv/bin/activate
pip install -r requirements.txt
  1. Run the tests
python tests.py
  1. Check for test coverage
coverage run tests.py
coverage report
Name                     Stmts   Miss  Cover
--------------------------------------------
ptapi42/__init__.py          1      0   100%
ptapi42/api42.py           219     29    87%
ptapi42/api42_token.py      26      5    81%
ptapi42/config.py           14      1    93%
tests.py                   163      0   100%
--------------------------------------------
TOTAL                      423     35    92%

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

ptapi42-1.0.6.tar.gz (12.3 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

ptapi42-1.0.6-py3-none-any.whl (11.5 kB view details)

Uploaded Python 3

File details

Details for the file ptapi42-1.0.6.tar.gz.

File metadata

  • Download URL: ptapi42-1.0.6.tar.gz
  • Upload date:
  • Size: 12.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.12.3

File hashes

Hashes for ptapi42-1.0.6.tar.gz
Algorithm Hash digest
SHA256 023c0f5e25a772d49266668783e16cfa70f68921c27c897f72de4eca5f31c22c
MD5 38e190e7615ffde63f9e813a37af966c
BLAKE2b-256 633b061ead22a443651e44dbc4a931dab165c3fdad0c84d6474b11ca6e70797c

See more details on using hashes here.

File details

Details for the file ptapi42-1.0.6-py3-none-any.whl.

File metadata

  • Download URL: ptapi42-1.0.6-py3-none-any.whl
  • Upload date:
  • Size: 11.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.12.3

File hashes

Hashes for ptapi42-1.0.6-py3-none-any.whl
Algorithm Hash digest
SHA256 e3d5859711525f2dd8899b3312156a2350b970ed7033b194a48cd2ea4200074f
MD5 5772b91cec31b49d8e87ee048c4eb6b0
BLAKE2b-256 4730a936516bdbe68e09c7191bc1909367331fcb1fc7fa87820baa44d078b2c2

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page