This library will create and validate JWT tokens
Project description
Description of the Encryption Module
This module provides essential functionalities for secure authentication and password management in Python applications, particularly useful in web services developed with FastAPI. It is designed with a focus on security, efficiency, and ease of use.
Features
JWT Token Management
create_jwt_token(payload: dict): Creates a JWT (JSON Web Token) with a custom payload, typically including user details like ID and role. The token is encrypted using a secret key and an algorithm specified in the environment variables. It has a default expiration of 7 days.check_token(token: str): Validates the given JWT token, verifying its integrity and authenticity. ReturnsTrueif the token is valid, otherwiseFalse.read_token_from_header(request: Request): Extracts and validates a JWT token from the HTTP request header. If the token is invalid or expired, it raises anHTTPExceptionwith appropriate status codes.read_token(token: str): Validates a given string token. Raises anHTTPExceptionif the token is invalid or expired, otherwise, returns the token's payload.
Password Encryption and Verification
encrypt_password(password: str): Encrypts a plain password using bcrypt, providing a secure way to store passwords.check_password(plain_password: str, hashed_password: str): Verifies a plain password against its hashed version, typically used during the login process.
This module is particularly suitable for web applications requiring robust authentication mechanisms and secure password handling.
Description of the Query Module
This module is designed to handle and validate query strings in Python applications, especially in the context of web APIs developed using FastAPI and Pydantic. It focuses on flexibility and reliability in processing and validating query strings.
Features
Query String Decoding
decode_query(query: str): Decodes a query string into a dictionary. It can handle both URL-encoded JSON strings and standard query strings. For JSON strings, it parses them into a dictionary, and for standard query strings, it processes them as key-value pairs.
Query Validation
decode_and_validate_query(query: str, validation_model: BaseModel): Decodes the given query string and then validates it against a specified Pydantic model. It ensures that the query matches the expected schema and data types.validate_query_over_schema(validation_model: BaseModel, query: dict): Validates a dictionary (typically the result of a decoded query) against a Pydantic model. It checks if all fields in the query are contained in the model and match the expected types. If the query is incorrect, it raises anHTTPExceptionwith details of the discrepancy.
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
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file api_service-0.0.3.tar.gz.
File metadata
- Download URL: api_service-0.0.3.tar.gz
- Upload date:
- Size: 4.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.0.1 CPython/3.11.11
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
2c6498d039e6bf7393ba1a89fa778ac47f7663193a2ffe6d9dfbe4a09ec67808
|
|
| MD5 |
4695a3f8a55fd0df137781e5b007634d
|
|
| BLAKE2b-256 |
beaed1eb3aa87eb45bb3eb89a0fb0e32c8464e383d4b70505153635e221a8d4e
|
File details
Details for the file api_service-0.0.3-py3-none-any.whl.
File metadata
- Download URL: api_service-0.0.3-py3-none-any.whl
- Upload date:
- Size: 4.9 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.0.1 CPython/3.11.11
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
f21b0aff0f3b5e3b248bc2ad35cd0cbc2573c146ad83e525ce26b0b29be707ba
|
|
| MD5 |
06f43903d8087de0930355c8a6e8b790
|
|
| BLAKE2b-256 |
124efb25d196ee3f935162c02dfaa1a224082fe6d037e4c8f31b83c0197bb951
|