A framework for building modular APIs with FastAPI, featuring CouchDB integration for dynamic 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
Release history Release notifications | RSS feed
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 fast_point_api-0.1.0.tar.gz.
File metadata
- Download URL: fast_point_api-0.1.0.tar.gz
- Upload date:
- Size: 11.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.0.1 CPython/3.12.0
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
13b2b29afe024bee1a2ff28922b5a6a4ec3587b77010e42bb39f4bdf150aedb2
|
|
| MD5 |
1c4a9ec61edce4bdd312ec74780732d9
|
|
| BLAKE2b-256 |
397acf2defd895f11ff0d97b7626cb27a28ac6b40881bc66280c2e47bcc7197a
|
File details
Details for the file fast_point_api-0.1.0-py3-none-any.whl.
File metadata
- Download URL: fast_point_api-0.1.0-py3-none-any.whl
- Upload date:
- Size: 11.8 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.0.1 CPython/3.12.0
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
9d069cd5b5cddbdb24d202488c6723ca75600b75c79c2b61dfa60f227149b787
|
|
| MD5 |
d28b7db0f4bbb319f8958665e5f00e5f
|
|
| BLAKE2b-256 |
91845df0840520ec4fe840620592db0d52a4bf89e81b0df40e354595c835c026
|