{"id":24269124,"url":"https://github.com/ricardo-agz/metro","last_synced_at":"2025-09-30T07:32:01.067Z","repository":{"id":257334826,"uuid":"857955635","full_name":"ricardo-agz/metro","owner":"ricardo-agz","description":"Metro is an opinionated, batteries-included Python web framework built on top of FastAPI and MongoEngine","archived":false,"fork":false,"pushed_at":"2025-01-16T09:28:55.000Z","size":745,"stargazers_count":5,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-01-16T10:54:23.480Z","etag":null,"topics":["api","fastapi","framework","json","mongodb","mongoengine","openapi","pydantic","python","python3","rails","rest"],"latest_commit_sha":null,"homepage":"","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/ricardo-agz.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2024-09-16T03:00:26.000Z","updated_at":"2025-01-16T09:28:56.000Z","dependencies_parsed_at":"2025-01-09T00:45:30.428Z","dependency_job_id":null,"html_url":"https://github.com/ricardo-agz/metro","commit_stats":{"total_commits":11,"total_committers":2,"mean_commits":5.5,"dds":0.09090909090909094,"last_synced_commit":"0870b0462d5aa36facec14ba91eecbd201278dab"},"previous_names":["ricardo-agz/pyrails","ricardo-agz/metro"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ricardo-agz%2Fmetro","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ricardo-agz%2Fmetro/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ricardo-agz%2Fmetro/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ricardo-agz%2Fmetro/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ricardo-agz","download_url":"https://codeload.github.com/ricardo-agz/metro/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":234448332,"owners_count":18834213,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["api","fastapi","framework","json","mongodb","mongoengine","openapi","pydantic","python","python3","rails","rest"],"created_at":"2025-01-15T14:51:17.922Z","updated_at":"2025-09-30T07:31:55.616Z","avatar_url":"https://github.com/ricardo-agz.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Metro\n\nMetro is a lightweight, opinionated, batteries-included Python web framework built on top of FastAPI and MongoEngine.   \nIt is means to provide helpful, lightweight abstractions to enable standard ways of implementing common patters to \nprevent the SaaSification of the developer stack. \n\n**The goal is to enhance not inhibit.**\n\n\n## Features\n\n- Built on top of FastAPI and MongoEngine ODM\n- CLI tool for project management and code generation\n- Built-in database management (MongoDB)\n- Support for both local and Docker-based development\n- Environment-specific configurations\n- Automatic API documentation\n\n---\n\n## Installation\n\nInstall Metro using pip:\n\n`pip install metroapi`\n\n---\n\n## Creating a New Project\n\nCreate a new Metro project using the `new` command:\n\n```\nmetro new my_project\ncd my_project\n```\n\nThis will create a new directory `my_project` with the default project structure:\n\n```\nmy_project/\n├── app/\n│   ├── controllers/\n│   ├── models/\n│   └── __init__.py\n├── config/\n│   ├── development.py\n│   ├── production.py  \n│   └── __init__.py\n├── main.py\n├── Dockerfile\n└── docker-compose.yml\n```\n\n---\n\n## Starting the Development Server\n\nStart the development server using the `run` command:\n\n```\nmetro run\n```\n\nThis will start the development server on http://localhost:8000.\n\n\nYou can also run the service using Docker:\n\n```\nmetro run --docker\n```\n\n---\n\n## Scaffolding Resources\n\nMetro includes a scaffold generator to quickly create models, controllers, and route definitions for a new resource.\n\nTo generate a scaffold for a `Post` resource with `title` and `body` fields:\n\n```\nmetro generate scaffold Post title:str body:str\n```\n\nThis will generate:\n\n- `app/models/post.py` with a `Post` model class\n- `app/controllers/posts_controller.py` with CRUD route handlers\n- Update `app/controllers/__init__.py` to import the new controller\n- Update `app/models/__init__.py` to import the new model \n\n\n### Scaffold Generator Options\n\n```\nmetro generate scaffold NAME [FIELDS...] [OPTIONS]\n```\n\n#### Available Options:\n\n`--actions`, `-a` (multiple): Define additional custom routes beyond CRUD operations\n\n* Format: `http_method:path (query: params) (body: params) (desc: description) (action_name: action_name)`\n* Example: `-a \"get:search (query: term:str) (desc: Search users) (action_name: search_users)\"`\n\n\n`--exclude-crud`, `-x` (multiple): Specify which CRUD operations to exclude\n\n* Choices: `index`, `show`, `create`, `update`, `delete`\n* Example: `-x delete -x update`\n\n\n`--model-inherits`: Specify base class(es) for the model\n\n* Format: Single class or comma-separated list\n* Example: `--model-inherits UserBase` or `--model-inherits \"UserBase,SomeMixin\"`\n\n\n`--controller-inherits`: Specify base class(es) for the controller\n\n* Format: Single class or comma-separated list\n* Example: `--controller-inherits AdminController`\n\n\n`--before-request`, `--before` (multiple): Add lifecycle hooks to run before each request\n\n* Format: `hook_name` or `hook_name:description`\n* Example: `--before \"check_admin:Verify admin access\"`\n\n\n`--after-request`, `--after` (multiple): Add lifecycle hooks to run after each request\n\n* Format: hook_name or hook_name:description\n* Example: --after \"log_action:Log all activities\"\n\n\n### Advanced Usage Examples\n\nFull CRUD scaffold with search and custom actions:\n\n```bash\nmetro generate scaffold Product name:str price:float \\\n  -a \"get:search (query: term:str,min_price:float,max_price:float) (desc: Search products) (action_name: search_products)\" \\\n  -a \"post:bulk-update (body: ids:list,price:float) (desc: Update multiple products) (action_name: bulk_update_products)\"\n```\n\nScaffold with limited CRUD and inheritance:\n\n```bash\nmetro generate scaffold AdminUser email:str role:str \\\n  --model-inherits \"UserBase,AuditableMixin\" \\\n  --controller-inherits AdminController \\\n  -x delete \\\n  --before \"check_admin:Verify admin permissions\" \\\n  --after \"log_admin_action:Log admin activities\"\n```\n\nCustom API endpoints with complex parameters:\n\n```bash\nmetro generate scaffold Order items:list:ref:Product status:str \\\n  -a \"post:process/{id} (body: payment_method:str) (desc: Process order payment) (action_name: process_order)\" \\\n  -a \"get:user/{user_id} (query: status:str,date_from:datetime) (desc: Get user orders) (action_name: get_user_orders)\"\n  --controller-inherits \"BaseController,PaymentMixin\"\n```\n\n\n#### Adding Custom Routes\nUse the `--actions` or `-a` option to add additional routes beyond the standard CRUD endpoints:\n\nex.\n```bash\nmetro generate scaffold Comment post_id:ref:Post author:str content:str --actions \"post:reply\"\n# or\nmetro generate scaffold Post title:str body:str -a \"post:publish\" -a \"get:drafts\"\n```\n\nThis will generate the standard CRUD routes plus two additional routes:\n- `POST /posts/publish`\n- `GET /posts/drafts`\n\n\n#### Excluding CRUD Routes\nUse the `--exclude-crud` or `-x` option to exclude specific CRUD routes you don't need:\n\n```bash\nmetro generate scaffold Post title:str body:str -x delete -x update\n```\n\nThis will generate a scaffold without the delete and update endpoints.\n\nYou can combine both options:\n\n```bash\nmetro generate scaffold Post title:str body:str -a \"post:publish\" -x delete\n```\n\n## Generating Models and Controllers\n\nYou can also generate models and controllers individually.\n\n### Generating a Model\n\nTo generate a `Comment` model with `post_id`, `author`, and `content` fields:\n\n```\nmetro generate model Comment post_id:str author:str content:str\n```\n\n### Model Generator Options\n\n```\nmetro generate model NAME [FIELDS...] [OPTIONS]\n```\n\n#### Available Options:\n\n`--model-inherits`: Specify base class(es) for the model\n\n* Format: Single class or comma-separated list\n* Example: `--model-inherits UserBase` or `--model-inherits \"UserBase,SomeMixin\"`\n\nExample with all options:\n\n```\nmetro generate model User email:str password:hashed_str profile:ref:Profile roles:list:str --model-inherits \"UserBase\"\n```\n\n### Generating a Controller\n\nTo generate a controller for `Auth` routes:\n\n```\nmetro generate controller Auth\n```\n\nYou can also pass in the routes to generate as arguments:\n\n```\nmetro generate controller Auth post:login post:register\n```\n\n### Controller Generator Options\n\n```\nmetro generate controller NAME [ACTIONS...] [OPTIONS]\n```\n\n#### Available Options:\n\n`--controller-inherits`: Specify base class(es) for the controller\n\n* Format: Single class or comma-separated list\n* Example: `--controller-inherits AdminController`\n\n`--before-request`, `--before` (multiple): Add lifecycle hooks to run before each request\n\n* Format: `hook_name` or `hook_name:description`\n* Example: `--before \"check_auth:Verify user authentication\"`\n\n`--after-request`, `--after` (multiple): Add lifecycle hooks to run after each request\n\n* Format: `hook_name` or `hook_name:description`\n* Example: `--after \"log_request:Log API request\"`\n\nExample with all options:\n```\nmetro generate controller Auth \\\n  \"post:login (body: email:str,password:str) (desc: User login)\" \\\n  \"post:register (body: email:str,password:str,name:str) (desc: User registration)\" \\\n  \"post:reset-password/{token} (body: password:str) (desc: Reset password)\" \\\n  --controller-inherits AuthBaseController \\\n  --before \"rate_limit:Apply rate limiting\" \\\n  --after \"log_auth_attempt:Log authentication attempt\"\n```\n\n## Field types\n\n### Basic Field Types:\n`str`, `int`, `float`, `bool`, `datetime`, `date`, `dict`, `list`.\n\n\n### Special Field Types:\n`ref`, `file`, `list:ref`, `list:file`, `hashed_str`.\n\n### Defining Model Relationships\n\nYou can define relationships between models using the following syntax:\n\n- **One-to-Many Relationship**: Use the `ref:` prefix followed by the related model name.\n\n```\nmetro generate model Post author:ref:User\n```\n\nThis will generate a `Post` model with an `author` field referencing the `User` model.\n\n- **Many-to-Many Relationship**: Use `list:` and `ref:` together.\n\n```\nmetro generate model Student courses:list:ref:Course\n```\n\nThis will generate a `Student` model with a `courses` field that is a list of references to `Course` models.\n\n### Field Modifiers\n`?` and `^`are used to define a field as optional or unique respectively.\n\n#### Optional Field: \nAppend `?` to the field name to mark it as optional.\n\n```\nmetro generate model User email?:str\n```\n\nThis will generate a `User` model with an optional `email` field.\n\n#### Unique Field: \nAppend `^` to the field name to specify it as unique.\n\n```\nmetro generate model User username^:str\n```\n\nThis will generate a `User` model with a unique `username` field.\n\n#### Field Choices:\nFor string fields that should only accept specific values, use the `choices` syntax with optional default value (marked with `*`):\n\n```bash\n# required role with no default value (role must be specified)\nmetro generate model User role:string:choices[user,admin]\n\n# optional role with default value of 'user'\nmetro generate model User role:string:choices[user*,admin]  # note it would be redundant to add ? here since the default value makes it optional\n```\n\nYou can combine these modifiers to create fields with multiple attributes:\n\n```bash\nmetro generate model Product \\\n  sku^:str \\                                  # unique identifier \n  name^:str \\                                 # unique name\n  price:float \\                               # no modifier makes price required\n  description?:str \\                          # optional description\n  status:string:choices[active*,discontinued] # enum with default value\n```\n\n#### Indexes:\nUse the `--index` flag to create indexes for more efficient querying. The syntax supports various MongoDB index options:\n\nNote that built in timestamp fields like `created_at`, `updated_at`, and `deleted_at` are automatically indexed and don't need to be specified.\n\n```bash\n# Basic single field index\nmetro generate model User email:str --index \"email\"\n\n# Basic compound index\nmetro generate model Product name:str price:float --index \"name,price\"\n\n# Unique compound index\nmetro generate model Product name:str price:float --index \"name,price[unique]\"\n\n# Compound index with descending order and sparse option\nmetro generate model Order total:float --index \"created_at,total[desc,sparse]\"  # note that created_at is a built-in field so it doesn't need to be defined explicitly\n```\n\nYou can specify multiple compound indexes:\n    \n```bash\nmetro generate model Product \\\n  name:str \\\n  price:float \\\n  category:str \\\n  --index \"name,price[unique]\" \\\n  --index \"category,created_at[desc,sparse]\"\n```\n\nThis will generate:\n\n```python\nclass Product(BaseModel):\n    name = StringField(required=True)\n    price = FloatField(required=True)\n    category = StringField(required=True) \n    created_at = DateTimeField(required=True)\n\n    meta = {\n        \"collection\": \"product\",\n        'indexes': [\n            {\n                'fields': ['name', 'price'],\n                'unique': True\n            },\n            {\n                'fields': ['-category', '-created_at'],\n                'sparse': True\n            }\n        ],\n    }\n```\n    \n#### Index Options:\n\n* `unique`: Ensures no two documents can have the same values for these fields\n* `sparse`: Only includes documents in the index if they have values for all indexed fields\n* `desc`: Creates the index in descending order (useful for sorting)\n\n## Specialty Field Types\n\n### Hashed Field \n`hashed_str` is a special field type that automatically hashes the value before storing it in the database.\n\n```\nmetro generate model User name:str password_hashed:str\n```\n\nThis will generate a `User` model with a `password` field stored as a hashed value.\n\n### File Fields\n`file` and `list:file` are special field types for handling file uploads. They automatically upload\nfiles to the specified storage backend (local filesystem, AWS S3, etc.) and store the file path and file metadata in the database.\n\n- **`file`**: Generates a single `FileField` on the model.\n- **`list:file`**: Generates a `FileListField`, allowing multiple files.\n\nExample usage:\n```\nmetro generate model User avatar:file\nmetro generate model Post attachments:list:file\n```\n\nThis will generate the following model classes:\n\n```python\nclass User(BaseModel):\n    avatar = FileField()\n    \nclass Post(BaseModel):\n    attachments = FileListField()\n```\n\nUploading files to s3 then becomes as easy as:\n\n```python\n# Set an individual file field\n@put('/users/{id}/update-avatar')\nasync def update_avatar(\n    self,\n    id: str,\n    avatar: UploadFile = File(None),\n):\n    user = User.find_by_id(id=id)\n    if avatar:\n        # This stages the file for upload\n        user.avatar = avatar\n        # This actually uploads the file and stores the metadata in the database\n        user.save()\n    \n    return user.to_dict()\n\n# Work with a list of files \n@post('/posts/{id}/upload-attachments')\nasync def upload_attachments(\n    self,\n    id: str,\n    attachments: list[UploadFile] = File(None),\n):\n    post = Post.find_by_id(id=id)\n    if attachments:\n        # This stages the new files for upload\n        post.attachments.extend(attachments)\n        # This actually uploads the files and adds appends to the attachments list in the db with the new metadata\n        post.save()\n    \n    return post.to_dict()\n```\n\n### File Storage Configuration\nThe default configuration is set to use the local filesystem and store files in the `uploads` directory. You can change the storage backend and location in the `config/development.py` or `config/production.py` file.\n\nDefault configuration:\n```python\nFILE_STORAGE_BACKEND = \"filesystem\"\nFILE_SYSTEM_STORAGE_LOCATION = \"./uploads\"\nFILE_SYSTEM_BASE_URL = \"/uploads/\"\n```\n\nCustom configuration in `config/development.py` or `config/production.py`:\n```python\nFILE_STORAGE_BACKEND = 'filesystem'\nFILE_SYSTEM_STORAGE_LOCATION = './uploads_dev'\nFILE_SYSTEM_BASE_URL = '/uploads_dev/'\n```\nOr to use AWS S3:\n```python\nFILE_STORAGE_BACKEND = 's3'\nS3_BUCKET_NAME = \"my-bucket\"\nAWS_ACCESS_KEY_ID = \"...\"\nAWS_SECRET_ACCESS_KEY = \"...\"\nAWS_REGION_NAME = \"us-east-1\"\n```\n\n---\n\n## Controllers\n\nControllers handle incoming HTTP requests and define the behavior of your API endpoints. Metro provides a simple, \ndecorator-based routing system similar to Flask or FastAPI.\n\n### Basic Controller\n    \n```python\nfrom metro.controllers import Controller, Request, get, post, put, delete\n\nclass UsersController(Controller):\n    meta = {\n        'url_prefix': '/users'  # Optional URL prefix for all routes in this controller\n    }\n\n    @get(\"/\")\n    async def index(self, request: Request):\n        return {\"users\": []}\n    \n    @post(\"/\")\n    async def create(self, request: Request):\n        user_data = await request.json()\n        return {\"message\": \"User created\"}\n    \n    ...\n```\n\n### Request Parameters\n```python\nfrom metro import Controller, Request, Body, Query, Path\n\nclass ProductsController(Controller):\n    @get(\"/search\")\n    async def search(\n        self,\n        request: Request,\n        query: str,               # Query parameter (?query=...)\n        category: str = None,     # Optional query parameter\n        page: int = 1,           # Query parameter with default value\n    ):\n        return {\"results\": []}\n\n    @post(\"/{id}/reviews\")\n    async def add_review(\n        self,\n        request: Request,\n        id: str,                 # Path parameter\n        rating: int = Body(...), # Body parameter (required)\n        comment: str = Body(None) # Optional body parameter\n    ):\n        return {\"message\": \"Review added\"}\n```\n\n### Response Types\n\nControllers can return various types of responses:\n\n```python\nfrom metro.responses import JSONResponse, HTMLResponse, RedirectResponse\n\nclass ContentController(Controller):\n    @get(\"/data\")\n    async def get_data(self, request: Request):\n        # Automatically converted to JSON\n        return {\"data\": \"value\"}\n    \n    @get(\"/page\")\n    async def get_page(self, request: Request):\n        # Explicit HTML response\n        return HTMLResponse(\"\u003ch1\u003eHello World\u003c/h1\u003e\")\n    \n    @get(\"/old-path\")\n    async def redirect(self, request: Request):\n        # Redirect response\n        return RedirectResponse(\"/new-path\")\n```\n\n### Error Handling\n\nMetro provides standard exceptions for common HTTP error cases:\n\n```python\nfrom metro.exceptions import NotFoundError, BadRequestError, UnauthorizedError\n\nclass ArticlesController(Controller):\n    @get(\"/{id}\")\n    async def show(self, request: Request, id: str):\n        article = None  # Replace with actual lookup\n        if not article:\n            raise NotFoundError(detail=\"Article not found\")\n        return article\n\n    @post(\"/\")\n    async def create(self, request: Request):\n        data = await request.json()\n        if \"title\" not in data:\n            raise BadRequestError(detail=\"Title is required\")\n        return {\"message\": \"Article created\"}\n```\n\n### Directory-Based URL Prefixes\n\nMetro automatically generates URL prefixes based on your controller's location in the directory structure. This helps \norganize your API endpoints logically:\n\n```\napp/controllers/\n├── users_controller.py          # Routes will be at /\n├── api/\n│   ├── v1/\n│   │   ├── posts_controller.py  # Routes will be at /api/v1\n│   │   └── tags_controller.py   # Routes will be at /api/v1\n│   └── v2/\n│       └── posts_controller.py  # Routes will be at /api/v2\n└── admin/\n    └── users_controller.py      # Routes will be at /admin\n```\n\n#### For example:\n\n```python\n# app/controllers/api/v1/posts_controller.py\nclass PostsController(Controller):\n    @get(\"/\")          # Final URL: /api/v1/posts\n    async def index(self, request: Request):\n        return {\"posts\": []}\n\n    @get(\"/{id}\")      # Final URL: /api/v1/posts/{id}\n    async def show(self, request: Request, id: str):\n        return {\"post\": {\"id\": id}}\n\n    # You can still add your own prefix that combines with the directory prefix\n    meta = {\n        'url_prefix': '/blog'  # Routes will be at /api/v1/blog\n    }\n```\n\n\n## Controller Lifecycle Hooks\n\nLifecycle hooks like `before_request` and `after_request` can be defined directly in a controller or inherited from a parent controller. Hooks are useful for tasks such as authentication, logging, or cleanup.\n\n### Example: AdminController and AdminUserController\n\n**`admin_controller.py`**\n```python\nfrom metro.controllers import Controller, before_request, after_request\nfrom metro.exceptions import UnauthorizedError\nfrom metro import Request\n\nclass AdminController(Controller):\n    @before_request\n    async def check_admin(self, request: Request):\n        is_admin = False  # Replace with actual logic\n        print(\"Checking admin status... (this will be run before each request)\")\n        if not is_admin:\n            raise UnauthorizedError(detail=\"Unauthorized access.\")\n\n    @after_request\n    async def cleanup_stuff(self, request: Request):\n        print(\"Cleaning up... (this will be run after each request)\")\n```\n\n**`admin_user_controller.py`**\n```python\nfrom app.controllers.admin_controller import AdminController\n\nclass AdminUserController(AdminController):\n    @get('/admin-user/all-users')\n    async def all_users(self, request):\n        return {\"users\": []}\n```\n\n### Key Points:\n- Hooks like `check_admin` and `after_request` can be defined directly in a controller or inherited from a parent.\n- In `AdminUserController`, hooks are inherited from `AdminController` and run before and after each request handler.\n\n### Execution:\n- If a `before_request` hook raises an exception (e.g., `UnauthorizedError`), the request handler is skipped, but the `after_request` hook still runs.\n\n---\n\n## Rate Limiting\n\nMetro includes a built-in rate limiter that can be applied to specific routes or controllers.\n\n### Throttling Controller Endpoints:\n\nTo apply rate limiting to a controller endpoint, use the `@throttle` decorator:\n\n```python\nfrom metro.rate_limiting import throttle\n\nclass UserController(Controller):\n    @get('/users/{id}')\n    @throttle(per_second=1, per_minute=10)\n    async def get_user(self, request: Request, id: str):\n        return {\"id\": id}\n```\n\n### Throttling Routes\n\nTo apply rate limiting to a specific route, pass the `Throttler` class as a dependency:\n\n```python\nfrom metro.rate_limiting import Throttler\n\n@app.get(\"/users/{id}\", dependencies=[Depends(Throttler(per_second=1, per_minute=10))]\nasync def get_user(request: Request, id: str):\n    return {\"id\": id}\n```\n\n### Customizing Rate Limiting\n\nParameters:\n- `name`: Namespace for the rate limiter.\n- `limits`: Compound rate limit definition. Can be a RateLimits() object or a function that returns a RateLimits() object.\n- `per_second`: Number of requests allowed per second.\n- `per_minute`: Number of requests allowed per minute.\n- `per_hour`: Number of requests allowed per hour.\n- `per_day`: Number of requests allowed per day.\n- `per_week`: Number of requests allowed per week.\n- `per_month`: Number of requests allowed per month.\n- `backend`: Rate limiting backend (e.g., `InMemoryRateLimiterBackend`, `RedisRateLimiterBackend`). Defaults to InMemoryRateLimiterBackend.\n- `callback`: Callback function to execute when the rate limit is exceeded. (request, limited, limit_info) =\u003e .... Defaults to raising a `TooManyRequestsError` if limit is exceeded.\n- `key`: Custom key function to generate a unique key for rate limiting. (request) =\u003e str. Defaults to request IP.\n- `cost`: Custom cost function to calculate the cost of a request. (request) =\u003e int. Defaults to 1.\n\n---\n\n## Email Sending\nEasily send emails using the built-in `EmailSender` class, which supports multiple email providers like Mailgun and AWS SES.\n\n```python\n# 1. Configure the provider:\n# - For Mailgun\nmailgun_provider = MailgunProvider(\n    domain=os.getenv(\"MAILGUN_DOMAIN\"), api_key=os.getenv(\"MAILGUN_API_KEY\")\n)\nmailgun_sender = EmailSender(provider=mailgun_provider)\n\n# - For AWS SES (coming soon)\nses_provider = AWSESProvider(region_name=\"us-west-2\")\nses_sender = EmailSender(provider=ses_provider)\n\n# 2. Send the email:\nmailgun_sender.send_email(\n    source=\"sender@example.com\",\n    recipients=[\"recipient@example.com\"],\n    subject=\"Test Email\",\n    body=\"This is a test email sent using Mailgun.\",\n)\n```\n\n---\n\n## SMS Sending\nEasily send SMS messages using the built-in `SMSSender` class, which supports multiple SMS providers like Twilio and Vonage.\n\n1. Add the provider credentials to the environment variables or config file:\n```\n# For Twilio\nTWILIO_ACCOUNT_SID=ACXXXXXXXXXXXXXXXX\nTWILIO_AUTH_TOKEN=your_auth_token\nTWILIO_PHONE_NUMBER=+1234567890\n\n# For Vonage\nVONAEG_API_KEY=your_api_key\nVONAGE_API_SECRET=your_api_secret\nVONAGE_PHONE_NUMBER=+1234567890\n```\n\n2. Send an SMS message:\n```python\nsms_sender = SMSSender()  # provider will be automatically detected based on environment variables but can also be specified explicitly\n\nsms_sender.send_sms(\n    source=\"+1234567890\",\n    recipients=[\"+1234567891\"],\n    message=\"This is a test SMS message!\",\n)\n```\n---\n\n## Database Management\n\nMetro provides commands to manage your MongoDB database.\n\n### Starting a Local MongoDB Instance\n\nTo start a local MongoDB instance for development:\n\n```\nmetro db up\n```\n\n### Stopping the Local MongoDB Instance\n\nTo stop the local MongoDB instance:\n\n```\nmetro db down\n```\n\n### Running MongoDB in a Docker Container\n\nYou can also specify the environment and run MongoDB in a Docker container:\n\n```\nmetro db up --env production --docker\n```\n\n---\n\n## Configuration\n\nEnvironment-specific configuration files are located in the `config` directory:\n\n- `config/development.py`\n- `config/production.py`\n\nHere you can set your `DATABASE_URL`, API keys, and other settings that vary between environments.\n\n---\n\n## Admin Panel\n\nMetro includes a built-in admin panel. You can view this at `/admin`\n\nYou can disable this or change the admin route in the `config/development.py` or `config/production.py` file:\n\n```python\nENABLE_ADMIN_PANEL = False\nADMIN_PANEL_ROUTE_PREFIX = \"/admin-panel\"\n```\n\n---\n\n## Conductor\n\n\"If the Rails generator was powered by an LLM\"\n\n### Configuring API Keys for Conductor\n\nAdd your OpenAI/Anthropic API keys to power Conductor\n\n`metro conductor setup add-key`\n\n`metro conductor setup list-keys`\n\n`metro conductor setup remove-key`\n\n### Initializing a New Project\n\nGenerate the starter code for a Metro project from a project description using the `init` command:\n\n`metro conductor init \u003cproject_name\u003e \u003cdescription\u003e`\n\nex.\n\n`metro conductor init my-app \"A social media app where users can make posts, comment, like, and share posts, and follow other users.\"`\n\n---\n\n## Documentation and Help\n\n- **API Documentation**: http://localhost:8000/docs\n- **CLI help**: `metro --help`\n\nFor guides, tutorials, and detailed API references, check out the Metro documentation site.\n\n---\n\n## License\n\nMetro is open-source software licensed under the MIT license.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fricardo-agz%2Fmetro","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fricardo-agz%2Fmetro","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fricardo-agz%2Fmetro/lists"}