Skip to main content

A package for building APIs with FastAPI, providing integration with CouchDB for managing collections and CRUD operations.

Project description

Fast Point API

Fast Point API is a framework for building APIs using FastAPI. It provides dynamic collection management and currently integrates with CouchDB. Future updates may include support for additional databases. This package is designed to simplify the creation of APIs for managing collections and CRUD operations.


Features

  • Automatically generates CRUD endpoints for collections.
  • Manages collections in a CouchDB instance, with potential future updates to support other databases.
  • Defines data structures using Pydantic schemas.

Installation

Install the package via pip:

pip install fast-point-api

Getting Started

Here's a quick example to set up your API:

Example Code

from fast_point_api.app_factory import create_app
from fast_point_api.schemas import PizzaModel, DrinkModel

# Define custom models
class MyModel(PizzaModel):
    extra_field: str

# CouchDB connection URL
connection_url = "http://admin:admin@localhost:5984"

# Define collections and models
collections = {
    "pizzas": PizzaModel,
    "bebidas": DrinkModel,
}

# Create the FastAPI app
app = create_app(connection_url=connection_url, models_dict=collections)

Run your app:

uvicorn main:app --reload

Visit the interactive API docs at http://127.0.0.1:8000/docs.


CouchDB Manager Example

The CouchDBManager class simplifies database management. Here's how to use it:

from fast_point_api.config import CouchDBManager

# Initialize CouchDBManager
manager = CouchDBManager(connection_url="http://admin:admin@localhost:5984")

# Get existing collections
collections = manager.get_existing_collections()
print(f"Existing collections: {collections}")

# Create or get a database
db = manager.get_db("example_db")

# Delete a specific collection
manager.delete_collection("example_db")

# Delete all collections (excluding system databases)
manager.delete_all_collections(exclude_system_dbs=True)

CRUD Operations Example

This package includes generic CRUD operations that you can use directly:

from fast_point_api.schemas import PizzaModel
from fast_point_api.crud import create_item, get_items, update_item

# Example Pizza data
pizza = PizzaModel(
    name="Pepperoni",
    description="Classic Pepperoni Pizza",
    ingredients="Tomato, Cheese, Pepperoni",
    size="Large",
    price=15.99,
    is_vegetarian=False,
)

# Create a new item
new_item = create_item(manager, "pizzas", pizza)
print(f"Created item: {new_item}")

# Retrieve all items
items = get_items(manager, "pizzas")
print(f"Items: {items}")

# Update an item
updated_data = {"price": 12.99}
updated_item = update_item(manager, "pizzas", new_item["_id"], updated_data)
print(f"Updated item: {updated_item}")

Configuration

CouchDB Setup

Ensure you have CouchDB running. You can use Docker to start an instance:

docker run -d -p 5984:5984 -e COUCHDB_USER=admin -e COUCHDB_PASSWORD=admin couchdb

API Endpoints

The package automatically generates CRUD endpoints for each collection. For example, for a collection named pizzas:

  • POST /pizzas/ - Create a new item.
  • GET /pizzas/ - Get all items.
  • GET /pizzas/{item_id} - Get a single item by ID.
  • PUT /pizzas/{item_id} - Update an item by ID.
  • DELETE /pizzas/{item_id} - Deactivate an item by ID.

Additionally, generic endpoints are available at /generic/{collection_name}/.


Dependencies

This package requires:

  • FastAPI
  • CouchDB
  • Uvicorn
  • Pydantic

Refer to requirements.txt for the full list of dependencies.


License

This project is licensed under the MIT License. See the LICENSE file for details.


Contributing

Contributions are welcome! Feel free to fork the repository and submit pull requests.


Contact

Author: MaynerAC
Email: mayneranahuacoaquira@gmail.com
GitHub: maynerac

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

fast_point_api-1.0.0.tar.gz (10.9 kB view details)

Uploaded Source

Built Distribution

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

fast_point_api-1.0.0-py3-none-any.whl (11.7 kB view details)

Uploaded Python 3

File details

Details for the file fast_point_api-1.0.0.tar.gz.

File metadata

  • Download URL: fast_point_api-1.0.0.tar.gz
  • Upload date:
  • Size: 10.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.0.1 CPython/3.12.8

File hashes

Hashes for fast_point_api-1.0.0.tar.gz
Algorithm Hash digest
SHA256 ea24343ba7288a9339b987a46f74e02ac3d555d2fa681f2e7954387b4fcbd2a4
MD5 e2987034ca1526c96a6a66e6585ab74e
BLAKE2b-256 51bf55e40cf784a31871923f3db33050a99807ff1705e2723ef80f14075929c9

See more details on using hashes here.

File details

Details for the file fast_point_api-1.0.0-py3-none-any.whl.

File metadata

  • Download URL: fast_point_api-1.0.0-py3-none-any.whl
  • Upload date:
  • Size: 11.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.0.1 CPython/3.12.8

File hashes

Hashes for fast_point_api-1.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 bd631dda5ed6749326b5ddf6b9ce7ef8df44f82256d191ba900ba020fb688975
MD5 61e88d86328a93c55d61b2509a6c150f
BLAKE2b-256 33f7b3828341845b092a8bc89fa154a309dfca16e7d4f8ee1b02d981f3231825

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