Package: ptapi42
ptapi42A 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.AcknowledgmentsThis API is highly influenced bydropi,
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 dropiWhile 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 bettermass_requestfunction to simplify requests that
involve multiple API endpoints.Supportptapi42 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 inissues.How to install (in prog)pipinstallptapi42How To Use Apifromptapi42importApi42,Api42Requestapi:Api42=Api42()# Making a simple GET requestcampus_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_requestreqs:list=[]foruserinusers:api_req=Api42Request(url=f"users/{user['id']}")reqs.append(api_req)user_info=api.mass_request('GET',reqs)Api ReferenceHow To Configure ApiThe Api has some configurations.fromptapi42importApi42api:Api42=Api42()Configure if you want Api42 to raise exceptionsapi.raises=TrueConfigure the max number of requests per secondapi.requests_per_second=8Configure Api log levelapi.log_lvl='DEBUG'api.log_lvl='INFO'api.log_lvl='WARNING'api.log_lvl='ERROR'api.log_lvl='FATAL'Running Tests (dev)Cloning the repository and switching to the testing branchgitclonegit@github.com:42-Portugal/ptapi42.gitcdptapi42Create a python environment and install the required packagespython-mvenvvenvsourcevenv/bin/activate
pipinstall-rrequirements.txtRun the testspythontests.pyCheck for test coveragecoverageruntests.py
coveragereport
NameStmtsMissCover
--------------------------------------------
ptapi42/__init__.py10100%
ptapi42/api42.py2192987%
ptapi42/api42_token.py26581%
ptapi42/config.py14193%
tests.py1630100%
--------------------------------------------
TOTAL4233592%