Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Python Ad Management with API for managing campaign and batch worker for storing campaigns to Ad Serving Cache with FastAPI, SQLAlchemy, Alembic, Pydantic, AsyncIO

NotificationsYou must be signed in to change notification settings

mehkey/python-ad-management-fastAPI-asyncio

Repository files navigation

Installation

  1. Install the python dependencies:pipenv install

  2. Install a local version of the database:docker compose up --build --remove-orphans -d

  3. Run database migration to have the latest schemas:alembic upgrade head

  4. Run the app locally:uvicorn app.main:app --reload

  5. Run the worker locally:python ad_management_worker.py

  6. Run Tests for the app locally: pytest ./app/main_test.py

Usage

The easiest way to get started with the api is to head over to the docs generated by fastapi atlocalhost:8000/docs.

  1. Create anadvertisor,campaign,adgroup,adUsing the endpointPOST /campaigns

API

POST /campaigns

Create a new campaign.

Request Body

  • name: string *
  • start_date: date *
  • end_date: date *
  • budget: float *
  • advertiser_id: int *
  • status: string
  • ad_groups:
    • "name": "string"
    • "targeting_criteria": "string"
    • "ads":
      • "title": "string"
      • "image_url": "string"
      • "destination_url": "string"

Example

{"name":"Test Ad Campaign","start_date":"2022-01-01T00:00:00","end_date":"2022-12-31T23:59:59","budget":1000.0,"ad_groups": [        {"name":"Test Ad Group","targeting_criteria":"Test targeting criteria","ads": [                {"title":"Test Ad","image_url":"http://test-image-url.com","destination_url":"http://test-destination-url.com"                }            ]        }    ]}

GET /campaigns/{id}

Get a campaign by ID.

Path Parameters

  • id: int *

Responses

  • 200: OK
  • 401: Unauthorized
  • 404: Campaign not found
  • 500: Internal Server Error

Example Result

[    {"id":1,"name":"Test Ad Campaign","start_date":"2022-01-01T00:00:00","end_date":"2022-12-31T23:59:59","budget":1000.0,"status":"CREATED","ad_groups": [            {"id":1,"name":"Test Ad Group","targeting_criteria":"Test targeting criteria","ads": [                    {"id":1,"title":"Test Ad","image_url":"http://test-image-url.com","destination_url":"http://test-destination-url.com"                    }                ]            }        ]    }]

FAST API

FAST API

Useful commands

python3 -m venv fenvsource fenv/bin/activatepip install pipenvpipenv installpipenv install <package> --devalembic revision -m "create all tables"alembic upgrade headalembic downgrade -1export PYTHONPATH=$PWD

Schema

Users

  • id: a unique identifier for each user, this field is the primary key and is of typeSERIAL.
  • username: a text field that stores the username of the user, this field is unique and is of typeVARCHAR(255).
  • email: a text field that stores the email of the user, this field is unique and is of typeVARCHAR(255).
  • password_hash: a text field that stores the hashed password of the user, this field is of typeVARCHAR(255).

Advertisers

  • id: a unique identifier for each advertiser, this field is the primary key and is of typeSERIAL.
  • name: a text field that stores the name of the advertiser, this field is of typeVARCHAR(255).
  • email: a text field that stores the email of the advertiser, this field is of typeVARCHAR(255).
  • phone_number: a text field that stores the phone number of the advertiser, this field is of typeVARCHAR(255).

AdCampaigns

  • id: a unique identifier for each ad campaign, this field is the primary key and is of typeSERIAL.
  • name: a text field that stores the name of the ad campaign, this field is of typeVARCHAR(255).
  • start_date: a date field that stores the start date of the ad campaign, this field is of typeDATE.
  • end_date: a date field that stores the end date of the ad campaign, this field is of typeDATE.
  • budget: a float field that stores the budget of the ad campaign, this field is of typeFLOAT.
  • advertiser_id: a foreign key that references the advertiser who created the ad campaign, this field is of typeINTEGER and references theid field of theAdvertisers table.
  • status: a text field that stores the current status of the ad campaign (e.g. "created", "running", "finished"), this field is of typeVARCHAR(255).

AdGroups

  • id: a unique identifier for each ad group, this field is the primary key and is of typeSERIAL.
  • name: a text field that stores the name of the ad group, this field is of typeVARCHAR(255).
  • targeting_criteria: a text field that stores the targeting criteria for the ad group, this field is of typeVARCHAR(255).
  • ad_campaign_id: a foreign key that references the ad campaign that the ad group belongs to, this field is of typeINTEGER and references theid field of theAdCampaigns table.

Ads

  • id: a unique identifier for each ad, this field is the primary key and is of type SERIAL.
  • title: a text field that stores the title of the ad, this field is of type VARCHAR(255).
  • image_url: a text field that stores the URL of the ad's image, this field is of type VARCHAR(255).
  • destination_url: a text field that stores the URL that the ad should redirect to when clicked, this field is of type VARCHAR(255).
  • ad_group_id: a foreign key that references the ad group that the ad belongs to, this field is of type INTEGER and references the id field of the AdGroups table.

About

Python Ad Management with API for managing campaign and batch worker for storing campaigns to Ad Serving Cache with FastAPI, SQLAlchemy, Alembic, Pydantic, AsyncIO

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

[8]ページ先頭

©2009-2025 Movatter.jp