api-service


Nameapi-service JSON
Version 0.0.4 PyPI version JSON
download
home_page
SummaryThis library will create and validate JWT tokens and decode and validate queries against a pydantic model in input. In order to work succesfully, it needs that you have defined the following environment variables: 'JWT_SECRET' your secret key for generating tokens,'JWT_ALGORITHM' your favorite algorithm to be use to generate the tokens
upload_time2024-01-04 17:26:57
maintainer
docs_urlNone
authorAlfonso Falcone
requires_python
license
keywords fastapi bcrypt jwt pydantic
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # 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. Returns `True` if the token is valid, otherwise `False`.
- `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 an `HTTPException` with appropriate status codes.
- `read_token(token: str)`: Validates a given string token. Raises an `HTTPException` if 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 an `HTTPException` with details of the discrepancy.



            

Raw data

            {
    "_id": null,
    "home_page": "",
    "name": "api-service",
    "maintainer": "",
    "docs_url": null,
    "requires_python": "",
    "maintainer_email": "",
    "keywords": "fastapi,bcrypt,jwt,pydantic",
    "author": "Alfonso Falcone",
    "author_email": "",
    "download_url": "https://files.pythonhosted.org/packages/e6/72/5fff914c07dbef381ec0fc8d6132fdf1a308673296986a68232d17aeb4d2/api_service-0.0.4.tar.gz",
    "platform": null,
    "description": "# Description of the Encryption Module\n\nThis 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.\n\n## Features\n\n### JWT Token Management\n\n- `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.\n- `check_token(token: str)`: Validates the given JWT token, verifying its integrity and authenticity. Returns `True` if the token is valid, otherwise `False`.\n- `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 an `HTTPException` with appropriate status codes.\n- `read_token(token: str)`: Validates a given string token. Raises an `HTTPException` if the token is invalid or expired, otherwise, returns the token's payload.\n\n### Password Encryption and Verification\n\n- `encrypt_password(password: str)`: Encrypts a plain password using bcrypt, providing a secure way to store passwords.\n- `check_password(plain_password: str, hashed_password: str)`: Verifies a plain password against its hashed version, typically used during the login process.\n\nThis module is particularly suitable for web applications requiring robust authentication mechanisms and secure password handling.\n\n# Description of the Query Module\n\nThis 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.\n\n## Features\n\n### Query String Decoding\n\n- `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.\n\n### Query Validation\n\n- `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.\n- `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 an `HTTPException` with details of the discrepancy.\n\n\n",
    "bugtrack_url": null,
    "license": "",
    "summary": "This library will create and validate JWT tokens         and decode and validate queries against a pydantic model in input.         In order to work succesfully, it needs that you have defined          the following environment variables: 'JWT_SECRET' your secret key         for generating tokens,'JWT_ALGORITHM' your favorite algorithm to be         use to generate the tokens",
    "version": "0.0.4",
    "project_urls": null,
    "split_keywords": [
        "fastapi",
        "bcrypt",
        "jwt",
        "pydantic"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "979b4a1caa2bb0462f83fa9278c9256e3936de252d0c142e1926af5b36994ceb",
                "md5": "df05029c852b4df0feec32ad28c3191e",
                "sha256": "571d7edf202f4725d75391fa1481f099acf7c2d855e11fe38a904300f2d88e74"
            },
            "downloads": -1,
            "filename": "api_service-0.0.4-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "df05029c852b4df0feec32ad28c3191e",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": null,
            "size": 4933,
            "upload_time": "2024-01-04T17:26:56",
            "upload_time_iso_8601": "2024-01-04T17:26:56.423406Z",
            "url": "https://files.pythonhosted.org/packages/97/9b/4a1caa2bb0462f83fa9278c9256e3936de252d0c142e1926af5b36994ceb/api_service-0.0.4-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "e6725fff914c07dbef381ec0fc8d6132fdf1a308673296986a68232d17aeb4d2",
                "md5": "e56d1de44c26795895a8fbba30f4b6b8",
                "sha256": "80308928b2c611d642ae26bbe92982c1e5924730227dba5c29c8d901b7b13b89"
            },
            "downloads": -1,
            "filename": "api_service-0.0.4.tar.gz",
            "has_sig": false,
            "md5_digest": "e56d1de44c26795895a8fbba30f4b6b8",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": null,
            "size": 4311,
            "upload_time": "2024-01-04T17:26:57",
            "upload_time_iso_8601": "2024-01-04T17:26:57.739830Z",
            "url": "https://files.pythonhosted.org/packages/e6/72/5fff914c07dbef381ec0fc8d6132fdf1a308673296986a68232d17aeb4d2/api_service-0.0.4.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-01-04 17:26:57",
    "github": false,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "lcname": "api-service"
}
        
Elapsed time: 0.19785s