Skip to main content

A Python library for accessing Hemnet.se property data

Project description

PyHemnet

PyPI version Python versions License: MIT Downloads

A Python library for accessing Hemnet.se property data. Extract property sales information including prices, locations, sizes, and detailed property characteristics.

Features

  • 🏠 Hemnet Data Access: Access property sales data from Hemnet.se

    • Get summary statistics on properties for sale and sold properties
    • Extract detailed information including prices, location, size, broker, and more
    • Filter by location and property types
    • Support for multiple property types (villa, radhus, bostadsrätt, etc.)
  • 🚀 Easy-to-use Python API

  • 💻 Object-oriented design with clean interfaces

Installation

Install from PyPI:

pip install pyhemnet

Or install from source:

git clone https://github.com/ningdp2012/pyhemnet.git
cd pyhemnet
pip install -e .

Quick Start

from pyhemnet import HemnetScraper, HemnetItemType

# Create a scraper instance
scraper = HemnetScraper()

# Get summary statistics
listing_count, sold_count = scraper.get_summary(location_id="17744")
print(f"Properties for sale: {listing_count}")
print(f"Sold properties: {sold_count}")

# Get detailed sold properties
homes = scraper.get_sold(
    location_id="17744",
    item_types=[HemnetItemType.VILLA, HemnetItemType.RADHUS]
)

for home in homes:
    print(f"{home['address']} - {home['final_price']} SEK")

Usage

Initialize the Scraper

from pyhemnet import HemnetScraper, HemnetItemType

scraper = HemnetScraper()

Get Summary Statistics

Get counts of properties for sale and sold:

# Get summary for a specific location
listing_count, sold_count = scraper.get_summary(location_id="17744")
print(f"For sale: {listing_count}, Sold: {sold_count}")

# Filter by property types
listing_count, sold_count = scraper.get_summary(
    location_id="17744",
    item_types=[HemnetItemType.VILLA]
)

Get Sold Properties

Retrieve detailed information about sold properties:

homes = scraper.get_sold(
    location_id="17744",
    item_types=[HemnetItemType.VILLA, HemnetItemType.RADHUS]
)

for home in homes:
    print(f"Address: {home['address']}")
    print(f"Final price: {home['final_price']} SEK")
    print(f"Asking price: {home['asking_price']} SEK")
    print(f"Living area: {home['living_area']}")
    print(f"Sold date: {home['sold_at']}")
    print("---")

Get Current Listings

Get properties currently for sale:

listings = scraper.get_listings(
    location_id="17744",
    item_types=[HemnetItemType.BOSTADSRATT]
)

for listing in listings:
    print(f"Address: {listing['address']}")
    print(f"Price: {listing['asking_price']} SEK")
    print(f"Published: {listing['published_at']}")

Property Types

Use the HemnetItemType enum or strings:

# Using enum (recommended)
item_types = [HemnetItemType.VILLA, HemnetItemType.RADHUS]

# Using strings
item_types = ["villa", "radhus"]

Available types:

  • VILLA - Detached houses
  • RADHUS - Townhouses
  • BOSTADSRATT - Condominiums
  • FRITIDSHUS - Vacation homes
  • TOMT - Land plots
  • GARD - Farms
  • OTHER - Other property types

Data Structure

Sold Property Data

Each sold property dictionary contains:

{
    'id': str,              # Hemnet ID
    'listing_id': str,      # Listing identifier
    'address': str,         # Street address
    'location': str,        # Location description
    'housing_type': str,    # Type of housing (Villa, Radhus, etc.)
    'rooms': int,           # Number of rooms
    'living_area': str,     # Living area with units
    'land_area': str,       # Land area with units
    'asking_price': int,    # Initial asking price in SEK
    'final_price': int,     # Final sold price in SEK
    'price_change': str,    # Price change information
    'sold_at': str,         # Sale date (YYYY-MM-DD format)
    'broker': str,          # Broker agency name
    'labels': list,         # List of property labels/tags
}

Current Listing Data

Each listing dictionary contains:

{
    'id': str,                      # Hemnet ID
    'address': str,                 # Street address
    'location': str,                # Location description
    'housing_type': str,            # Type of housing
    'rooms': int,                   # Number of rooms
    'living_area': str,             # Living area with units
    'land_area': str,               # Land area with units
    'asking_price': int,            # Asking price in SEK
    'published_at': str,            # Publication date (YYYY-MM-DD)
    'removed_before_showing': bool, # Removed before showing
    'new_construction': bool,       # New construction flag
    'broker_name': str,             # Broker name
    'broker_agent': str,            # Broker agency name
    'labels': list,                 # List of property labels/tags
    'description': str,             # Property description
}

Finding Location IDs

To find Hemnet location IDs:

  1. Go to Hemnet.se
  2. Search for your desired location
  3. Look at the URL - it contains location_ids[]=XXXXX
  4. Use that ID in your code

Example: For Stockholm https://www.hemnet.se/bostader?location_ids[]=17744, use location_id="17744"

Requirements

  • Python 3.10+
  • cloudscraper >= 1.2.71
  • beautifulsoup4 >= 4.12.0
  • requests >= 2.31.0

Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

License

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

Disclaimer

This package is created for exploring python and web technologies and learning purposes only. It is not intended for production use or commercial applications.

  • This is an unofficial package and is not affiliated with or endorsed by Hemnet AB
  • Always respect website terms of service and robots.txt directives
  • Web scraping may be subject to legal restrictions in your jurisdiction
  • Use at your own risk and responsibility

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

pyhemnet-0.2.0.tar.gz (11.4 kB view details)

Uploaded Source

Built Distribution

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

pyhemnet-0.2.0-py3-none-any.whl (8.5 kB view details)

Uploaded Python 3

File details

Details for the file pyhemnet-0.2.0.tar.gz.

File metadata

  • Download URL: pyhemnet-0.2.0.tar.gz
  • Upload date:
  • Size: 11.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.3

File hashes

Hashes for pyhemnet-0.2.0.tar.gz
Algorithm Hash digest
SHA256 eed3e426a489fb3a0307b3e4dfbafd1a07724bde4b022e8f172f711a3ffe37db
MD5 14dd8d4b3c2b0b74dcf9c8790c80a488
BLAKE2b-256 68c8608019dd7acee9fa75aee958530c9b82ce008d364e314078c8c1881539b2

See more details on using hashes here.

File details

Details for the file pyhemnet-0.2.0-py3-none-any.whl.

File metadata

  • Download URL: pyhemnet-0.2.0-py3-none-any.whl
  • Upload date:
  • Size: 8.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.3

File hashes

Hashes for pyhemnet-0.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 99525342edc3b6c304d79de3e6b56a608a50c84eafe29dbbc8c867231938e9e5
MD5 df53da0f4af321d0b7f0bf9b6abd3bc1
BLAKE2b-256 bc8d62debe6f2f052228152cb553fa2b4eb80da0d3b1fc6ca43687e6cb8a8ff5

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