This directory contains comprehensive specifications for building Python PyPI packages for the countries-states-cities-database project, mirroring the existing npm package ecosystem.
Complete specifications for the Python package ecosystem
Key Topics:
- Executive summary and business context
- Repository architecture and directory structure
- Detailed package specifications (countries, timezones, currencies, etc.)
- Pydantic models and type definitions
- API design and function signatures
- Data loading strategies with LRU caching
- Development tooling (Poetry, pytest, mypy)
- CI/CD with GitHub Actions
- Testing requirements and strategies
- Documentation structure
- Implementation roadmap (4-6 weeks)
When to Use: Start here for complete understanding of the project scope and architecture.
Side-by-side comparison of npm and Python implementations
Key Topics:
- Package naming conventions
- Installation and usage examples
- Type systems (TypeScript vs Pydantic)
- Data loading approaches
- Testing frameworks
- Build tools and toolchains
- CI/CD workflows
- Framework integration examples
- API style differences
When to Use: Reference this when making design decisions to ensure consistency with npm packages.
Step-by-step implementation guide for the first package
Key Topics:
- Phase 1: Setup (directory structure, Poetry)
- Phase 2: Core implementation (models, loaders, API)
- Phase 3: Testing (pytest, coverage)
- Phase 4: Data generation (MySQL to JSON)
- Phase 5: Package configuration (pyproject.toml)
- Phase 6: Build and test
- Phase 7: Publish to PyPI
- Complete code examples
- Pre-launch checklist
- Troubleshooting tips
When to Use: Follow this guide for hands-on implementation of the first package.
| Type | NPM | Python |
|---|---|---|
| Countries | @countrystatecity/countries |
countrystatecity-countries |
| Timezones | @countrystatecity/timezones |
countrystatecity-timezones |
| Currencies | @countrystatecity/currencies |
countrystatecity-currencies |
| Languages | @countrystatecity/languages |
countrystatecity-languages |
| Phone Codes | @countrystatecity/phone-codes |
countrystatecity-phonecodes |
# NPM
npm install @countrystatecity/countries
# Python
pip install countrystatecity-countries# Python
from countrystatecity_countries import get_countries, get_country_by_code
countries = get_countries()
usa = get_country_by_code("US")// TypeScript
import { getCountries, getCountryByCode } from '@countrystatecity/countries';
const countries = await getCountries();
const usa = await getCountryByCode('US');countries-states-cities-database/
βββ bin/ # [Existing] PHP export tools
βββ contributions/ # [Existing] JSON source data
βββ json/ # [Existing] JSON exports
βββ sql/ # [Existing] SQL dumps
β
βββ python/ # [NEW] Python packages
β βββ packages/
β β βββ countries/ # Priority 1
β β βββ timezones/ # Priority 2
β β βββ currencies/ # Priority 3
β β βββ languages/ # Priority 4
β β βββ phone-codes/ # Priority 5
β βββ shared/ # Shared utilities
β βββ scripts/ # Build scripts
β βββ README.md
β
βββ specs/ # [THIS FOLDER] Specifications
βββ README.md # This file
βββ 1-python-pypi-monorepo-plan.md
βββ 2-python-vs-npm-comparison.md
βββ 3-python-quick-start-guide.md
Package: countrystatecity-countries
- Setup repository structure
- Implement core functionality
- Write comprehensive tests
- Generate data structure
- Publish to PyPI
Packages:
countrystatecity-timezonescountrystatecity-currencies
Packages:
countrystatecity-languagescountrystatecity-phonecodes
Packages:
countrystatecity-flaskcountrystatecity-django
- Same data structure
- Similar API design (adapted for Python conventions)
- Identical functionality
- Type hints everywhere (Pydantic models)
- PEP 8 compliant (black, isort)
- Comprehensive testing (pytest, 80%+ coverage)
- Modern packaging (Poetry, pyproject.toml)
- Lazy loading with LRU cache
- Minimal memory footprint
- Fast import times (<50ms)
- Split data files for granular loading
- Clear API documentation
- Type safety with mypy
- Comprehensive examples
- Easy integration with frameworks
- Single source of truth (MySQL database)
- Automated data generation
- Validation at build time
- Immutable models (Pydantic frozen)
| Component | Technology | Purpose |
|---|---|---|
| Package Manager | Poetry | Dependency management, publishing |
| Type System | Pydantic | Data validation, immutable models |
| Testing | pytest | Unit and integration tests |
| Type Checking | mypy | Static type checking |
| Linting | ruff | Fast Python linter |
| Formatting | black + isort | Code formatting |
| CI/CD | GitHub Actions | Automated testing and publishing |
| Data Source | MySQL | Primary database |
| Data Format | JSON | Lazy-loadable data files |
- β Test coverage: 80%+
- β Type coverage: 100% (mypy strict mode)
- β Import time: <50ms
- β Memory footprint: <10MB (base)
- β Load time: <100ms (per country)
- β Zero critical bugs
- β Issue response time: <48 hours
- β Documentation completeness: 100%
- β API consistency with npm packages
- π PyPI downloads per week
- β GitHub stars
- π Issue resolution rate
- π€ Community contributions
-
Read the specifications
- Start with 1-python-pypi-monorepo-plan.md
- Review 2-python-vs-npm-comparison.md
-
Follow the quick start guide
- Use 3-python-quick-start-guide.md
- Complete Phase 1 (Setup)
- Implement Phase 2 (Core functionality)
-
Test and iterate
- Write tests alongside code
- Run mypy for type checking
- Use black and isort for formatting
-
Publish and monitor
- Publish to TestPyPI first
- Then publish to PyPI
- Monitor downloads and issues
-
Understand the architecture
- Read all specification documents
- Review existing npm packages
- Understand data structure
-
Set up development environment
- Install Python 3.8+
- Install Poetry
- Clone repository
-
Make changes
- Follow coding standards
- Write tests
- Update documentation
-
Submit PRs
- Ensure tests pass
- Include documentation
- Reference related issues
- npm packages repository
- API documentation
- Pydantic documentation
- Poetry documentation
- PyPI packaging guide
- Large Python community needs official packages
- Server-side and data science use cases
- Better integration with Django, Flask, FastAPI
- Avoid outdated/incomplete alternatives
- Python developers expect native Python packages
- Better performance without JavaScript bridge
- Type safety with Pydantic
- Pythonic API design
- Single source of truth: MySQL database
- Automated data generation scripts
- Same JSON structure as npm packages
- CI/CD ensures consistency
- Start with PyPI (most common)
- Can publish to Conda later if demand exists
- Focus on quality over quantity
For questions or clarifications about these specifications:
- Issues: GitHub Issues
- Discussions: GitHub Discussions
- Email: Contact via API website
Last Updated: January 2025
Status: Ready for Implementation
Next Action: Begin Phase 1 of Quick Start Guide